#include "Bullet.h"
#include "RSManager.h"
#include "Box.h"
#include "Sprite.h"
//thao chinh chut cho nay 0.6f-> 0.3f

#include "GameDefine.h"


Bullet::Bullet():MoveObject(),Object(new Box(D3DXVECTOR2(),D3DXVECTOR2(),D3DXVECTOR2(BULLET_SPEED,BULLET_SPEED)),ObjBullet)
{
	_range = ATTACK_RANGE;
	_id = B_E;
}

Bullet::~Bullet()
{
}

void Bullet::init(BULLET_ID id)
{		
	//
	_id = id;
	switch (id)
	{
	case B_R:
		_sprite = RSManager::getInstance()->getSprite(BR);
		break;
	case B_M:
		_sprite = RSManager::getInstance()->getSprite(BM);
		break;
	case B_S:
		_sprite = RSManager::getInstance()->getSprite(BM);
		break;
	case B_F:
		_sprite = RSManager::getInstance()->getSprite(BR);
		break;
	case B_L:
		_sprite = RSManager::getInstance()->getSprite(BL);
		break;
	case B_E:
		_sprite = RSManager::getInstance()->getSprite(BE);
		break;
	}

	_box->_size =  _sprite->getRenderSize();
	this->AssignMove(_box);
}

void Bullet::loaded(ObjectType parent,D3DXVECTOR2 pos, float angle)
{	
	_box->_position = pos;
	_angle = angle;	
}

void Bullet::update()
{
	this->moveFollowAngle(GAME_TIME, this->_angle);
	_range -= GAME_TIME*BULLET_SPEED;

}

void Bullet::render()
{	
	_sprite->Render(_box->_position);	
}

bool Bullet::hasLife()
{		
	if (_range < 0)	
	{
		_range = ATTACK_RANGE;
		return true;	
	}
	return false;
}

BULLET_ID Bullet::getType()
{
	return _id;
}
